﻿using System;
using System.Text;
using Assist;
using Autodesk.Revit.DB;

namespace YJKRevitDimension.ElevationDimension
{
	public class ShowLevel
	{
		public ShowLevel(Level level)
		{
			this.Level = level;
		}

		public override string ToString()
		{
			return this.Level.Name;
		}

		public int NumLength
		{
			get
			{
				return ((int)(AssistFunc.feetToMM(this.Level.Elevation) / 1000.0)).ToString().Length;
			}
		}

		private int GetLength(string str)
		{
			if (str.Length == 0)
			{
				return 0;
			}
			Encoding encoding = new ASCIIEncoding();
			int num = 0;
			byte[] bytes = encoding.GetBytes(str);
			for (int i = 0; i < bytes.Length; i++)
			{
				if (bytes[i] == 63)
				{
					num += 2;
				}
				else
				{
					num++;
				}
			}
			return num;
		}

		public int StrLength
		{
			get
			{
				return this.GetLength(this.Level.Name);
			}
		}

		public string GetValueString(int maxLength, bool numAtLeft)
		{
			if (numAtLeft)
			{
				string text = "";
				for (int i = 0; i < maxLength - this.NumLength; i++)
				{
					text += " ";
				}
				return Math.Round(AssistFunc.feetToMM(this.Level.Elevation) / 1000.0, 3).ToString("0.000").Insert(0, text) + "  " + this.Level.Name;
			}
			string text2 = "";
			for (int j = 0; j < maxLength - this.StrLength; j++)
			{
				text2 += " ";
			}
			return this.Level.Name.Insert(0, text2) + "  " + Math.Round(AssistFunc.feetToMM(this.Level.Elevation) / 1000.0, 3).ToString("0.000");
		}

		public Level Level;
	}
}
